package com.com.knowledgepaymentmanagementsystem.controller.assets;

import com.com.knowledgepaymentmanagementsystem.anno.Log;
import com.com.knowledgepaymentmanagementsystem.pojo.assets.Assets;
import com.com.knowledgepaymentmanagementsystem.service.assets.AssetsService;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张攀
 * @version 1.0
 * @description: TODO
 * @date 2025/9/23 上午10:45
 */
@Api(tags = "资产管理")
@RestController
@CrossOrigin
@RequestMapping("/assets")
public class AssetsController {

    @Autowired
    private AssetsService assetsService;


    @ApiOperation(value = "资产查询",httpMethod = "POST",notes = "资产查询")
    @PostMapping("/find")
    public ResultUtil<List<Assets>> selectAssets(@RequestBody Assets assets){
        try {
            return new ResultUtil<List<Assets>>(200,"查询成功",assetsService.selectAssets(assets));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"查询失败");
        }
    }

    @Log
    @ApiOperation(value = "新增资产",httpMethod = "POST",notes = "新增资产")
    @PostMapping("insert")
    public ResultUtil insertAssets(@RequestBody Assets assets){
        try {
            return new ResultUtil<>(200,"新增成功",assetsService.insertAssets(assets));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"新增失败");
        }
    }

    @Log
    @ApiOperation(value = "修改资产",httpMethod = "PUT",notes = "修改资产")
    @PutMapping("/update")
    public ResultUtil updateAssets(@RequestBody Assets assets){

        assetsService.updateAssets(assets);
        try {
            return new ResultUtil(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"修改失败");

        }
    }

    @Log
    @ApiOperation(value = "删除资产",httpMethod = "DELETE",notes = "删除资产")
    @DeleteMapping("/delete")
    public ResultUtil deleteAssets(Integer id){
        assetsService.deleteAsses(id);
        try {
            return new ResultUtil(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"删除失败");

        }
    }
}
